package com.shanghaiyimu.yimiyangche.activity;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.adapter.MyViewPageAdapter;

import java.util.ArrayList;
import java.util.List;

public class WelcomeActivity extends AppCompatActivity {

    private Button button;
    private ViewPager viewPager;
    private List<View> data = null;
    private MyViewPageAdapter adapter = null;
    private View[] views = new View[4];
    private int[] viewId = {R.layout.view1,R.layout.view2,R.layout.view3, R.layout.view4};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        init();

        adapter = new MyViewPageAdapter(data);
        viewPager.setAdapter(adapter);
    }

    private void init() {

        viewPager = (ViewPager) findViewById(R.id.activity_welcome_viewPage);
        data = new ArrayList<>();
        for (int i = 0;i < viewId.length;i++){
            views[i] = View.inflate(this,viewId[i],null);
            data.add(views[i]);
        }
        button = (Button) views[3].findViewById(R.id.view_welcome_textView_go);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(WelcomeActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }

}
